class Node{
    constructor(element){
        this.element = element
        this.right=null
        this.left = null
    }
}
class Tree{
    constructor(){
        this.root = null
        this.count=0
        this.leftCount = 1
        this.rightCount = 1
    }
    insert(element){//添加的方法
        let node = new Node(element);
        if(this.root===null){
            this.root=node
        }else{
            this.insertNode(node,this.root)
        }
    }
    insertNode(newNode,rootNode){
        if(newNode.element<rootNode.element){
           if(rootNode.left==null){
               rootNode.left=newNode
           }else{
               this.insertNode(newNode,rootNode.left)
           }
        }else{
            if(rootNode.right==null){
                rootNode.right=newNode
            }else{
                this.insertNode(newNode,rootNode.right)
            }
        }
    }
    lou(){//读取层数
        this.leftJia(this.root)
        this.rightJia(this.root)
        if(this.leftCount>this.rightCount){
           return this.leftCount
        }else{
            return this.rightCount
        }
    }
    leftJia(rootNode){
        if(rootNode.left!==null){
            this.leftCount++
            this.leftJia(rootNode.left)
        }
        return 
    }
    rightJia(rootNode){
        if(rootNode.right!==null){
            this.rightCount++
            this.rightJia(rootNode.right)
        }
        return 
    }
    // preOrderTraverse(){//遍历
    //     this.preOrderTraverseNode(this.root)
    // }
    // preOrderTraverseNode(rootNode){
    //     if(rootNode!=null){
    //         console.log(rootNode.element)
    //         this.preOrderTraverseNode(rootNode.left)
    //         this.preOrderTraverseNode(rootNode.right)
    //     }   
    // }
}
let t = new Tree()
t.insert(15)
t.insert(14)
t.insert(13)
t.insert(8)
t.insert(2)
t.insert(3)
t.insert(9)
// t.preOrderTraverse()
console.log(t.lou());

